﻿/// <reference path="../jquery-1.5.1-vsdoc.js" />

$(function () {
    $countDowns = $(".clockCountDown");
    setTimeout(countDownFunc, 1000);
});


countDownFunc = function () {
    $.each($countDowns, function (index, value) {
        var $d = $(value).children(".clock-days");
        var $h = $(value).children(".clock-hours");
        var $m = $(value).children(".clock-minutes");
        var $s = $(value).children(".clock-seconds");

        var d = parseInt($d.text());
        var h = parseInt($h.text());
        var m = parseInt($m.text());
        var s = parseInt($s.text());
        if (s > 0) {
            s--;
        }
        else if (s == 0) {
            if (m > 0) {
                m--;
                s = 59;
            }
            else if (m == 0) {
                if (h > 0) {
                    h--;
                    m = 59;
                }
                else if (h == 0) {
                    if (d > 0) {
                        d--;
                        h = 23;
                    }
                }
            }
        }
        $d.text(d);
        $h.text(h);
        $m.text(m);
        $s.text(s);
    });
    setTimeout(countDownFunc, 1000);
}
    